//
//  ProductListController.m
//  ProductDemo
//
//  Created by hoho on 14-11-7.
//  Copyright (c) 2014年 hoho. All rights reserved.
//

#import "ProductListController.h"
#import "AFHTTPRequestOperationManager.h"
#import "MJRefresh.h"
#import "UIView+Toast.h"
#import "UIImageView+WebCache.h"
#import "MyList.h"

@interface ProductListController ()

@end

@implementation ProductListController{
    MyList *list;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    list = [[MyList alloc]init];
    list.tableV = _tv;
    list.view = self.view;
    list.parameter = [NSMutableDictionary dictionary];
    [list.parameter addEntriesFromDictionary:@{@"do":@"Product/index"}];
    NSString *cid = [NSString stringWithFormat:@"%lu",(unsigned long)_cid];
    [list.parameter addEntriesFromDictionary:@{@"cid":cid}];
    
    [list setupRefresh];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view Data Source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [list.data count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProductCell"];
    
    UIImageView *imageView = (UIImageView *)[cell viewWithTag:100];
    NSString *imageURL = [[list.data objectAtIndex:indexPath.row] objectForKey:@"image"];
    [imageView sd_setImageWithURL:[NSURL URLWithString:imageURL]
        placeholderImage:[UIImage imageNamed:@"imageholder.png"]
        completed:^(UIImage *image, NSError *error, SDImageCacheType cacheTyp, NSURL *imageURL){}
     ];
    UILabel *titleView = (UILabel *)[cell viewWithTag:101];
    titleView.text = [[list.data objectAtIndex:indexPath.row] objectForKey:@"title"];
    UILabel *contentView = (UILabel *)[cell viewWithTag:102];
    contentView.text = [[list.data objectAtIndex:indexPath.row] objectForKey:@"content"];
    return cell;
    
}


@end
